package com.css.crm.utility;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 * 
 * @author AIS
 *
 */
public class SystemUtil {

	/**
	 * add message show
	 * @param message
	 */
	public static void addMessage(String message){
		FacesContext context = FacesContext.getCurrentInstance();
		if(context == null){
			return;
		}
		FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO, message, null);
		context.addMessage(null, facesMessage);
	}
	
	public static void addMessageError(String message){
		FacesContext context = FacesContext.getCurrentInstance();
		if(context == null){
			return;
		}
		FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null);
		context.addMessage(null, facesMessage);
	}
	
	public static void addMessageError(String id, String message){
		FacesContext context = FacesContext.getCurrentInstance();
		if(context == null){
			return;
		}
		FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null);
		context.addMessage(id, facesMessage);
	}
	
	public static void saveSession(String key, Object value){
		FacesContext fc = FacesContext.getCurrentInstance();	
		if(fc == null){
			return;
		}
		fc.getExternalContext().getSessionMap().put(key, value);
	}
	
	public static Object getSession(String key){
		FacesContext fc = FacesContext.getCurrentInstance();
		if(fc == null){
			return null;
		}
		return fc.getExternalContext().getSessionMap().get(key);
	}
}
